package cn.gson.springboot.controller;

import cn.gson.springboot.model.pojos.PaymentInvoice;
import cn.gson.springboot.model.service.PaymentInvoiceService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class PaymentInvoiceController {
    @Autowired
    PaymentInvoiceService payInvoiceService;

    @RequestMapping("pay-invoice-list")
    @ResponseBody
    public Map<String,Object> payInvoiceList(Integer page,Integer size,Integer value,Integer num,String payDate){
        Page<Object> obj = PageHelper.startPage(page, size);
        List<PaymentInvoice> pay = payInvoiceService.selectPaymentInvoice(value, num,payDate);
        Map<String,Object> map = new HashMap<>();
        map.put("rows",pay);
        map.put("total",obj.getTotal());
        return map;
    }

    @RequestMapping("pay-invoice-past-future-thirty-list")
    @ResponseBody
    public List<PaymentInvoice> payInvoiceDateList(){
        List<PaymentInvoice> pay = payInvoiceService.selectPaymentInvoicePastFutureThirty();
        return pay;
    }

    @RequestMapping("pay-invoice-pur-list")
    @ResponseBody
    public List<PaymentInvoice> payInvoiceDateList(Integer page,Integer size,Integer purId){
        List<PaymentInvoice> pay = payInvoiceService.selectPaymentInvoiceByPurId(purId);
        return pay;
    }

    @RequestMapping("save-pay-invoice")
    @ResponseBody
    public void savePayInvoice(@RequestBody PaymentInvoice pay){
       payInvoiceService.savePaymentInvoice(pay);
    }

    @RequestMapping("delete-pay-invoice")
    @ResponseBody
    public void deletePayInvoice(@RequestParam(value = "payId") Integer payId){
        payInvoiceService.deletePaymentInvoice(payId);
    }
}
